import {connect} from 'dva';
import style from './index.css';
import { Form, Icon, Input, Button, Checkbox ,message} from 'antd';
import React from 'react'

function Login(props) {

const handleSubmit=(e)=> {
    e.preventDefault();
    props.form.validateFields((err, values) => {
      if(values.userName == 'admin' && values.password == 'admin'){
        if (!err) {
        props.dispatch({
          type:'info/getData',
          payload:{
            userName:values.userName,
            password:values.password
          },
          callback: (res) => {
            if (res) {
              console.log(res);// 请求完成后返回的结果
            }
          }        
        })
      }
      }else{
        alert('请输入正确的账号或密码！')
        location.reload()
      }
      
    });
  }
  
    const { getFieldDecorator } = props.form;
   

    return (
      <Form onSubmit={handleSubmit} className={style.login}>
        <h2 className={style.title}>TRENDIANO后台管理系统</h2>
       
        <Form.Item>
          {getFieldDecorator('userName', {
            rules: [{ required: true, message: '请输入您的账户!' }],
          })(
            <Input
              prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />}
              placeholder="请输入您的用户名"
            />,
          )}
        </Form.Item>
        <Form.Item>
          {getFieldDecorator('password', {
            rules: [{ required: true, message: '请输入您的密码!' }],
          })(
            <Input
              prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />}
              type="password"
              placeholder="请输入您的密码"
            />,
          )}
        </Form.Item>
        <Form.Item>
          <p>用户名密码都为admin</p>
          <Button type="primary"
          htmlType="submit" className={style.button}>
            登录
          </Button>
        </Form.Item>
      </Form>
    );

}

const WrappedNormalLoginForm = Form.create({ name: 'normal_login' })(Login);


export default connect(state=>state.info)(WrappedNormalLoginForm)